<template>
	<div class="app-container">
		<el-form class="filter-container" ref="dataForm" :model="listQuery" label-position="left" label-width="68px">
			<el-row :gutter="24">
				<el-button class="filter-item" @click="handleAdd" type="success" icon="el-icon-plus" style="margin-left:20px;">新增</el-button>
			</el-row>
			<el-row :gutter="24">
				<el-col :span="5">
					<el-form-item label="标题" style="margin-bottom: 0!important;">
						<el-input clearable @keyup.enter.native="getList" class="filter-item" placeholder="请输入搜索内容" v-model.trim="listQuery.eventTitle"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="5">
					<el-form-item label="标签" style="margin-bottom: 0!important;">
						<el-input clearable @keyup.enter.native="getList" class="filter-item" placeholder="请输入搜索内容" v-model.trim="listQuery.keyword"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="9">
					<el-form-item label="发现时间" style="margin-bottom: 0!important;">
						<el-date-picker type="datetimerange" :default-foundTime="['00:00:00', '23:59:59']" @keyup.enter.native="getList" class="filter-item" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" v-model="listQuery.foundTime" :picker-options="pickerOptions" clearable></el-date-picker>
					</el-form-item>
				</el-col>
				<el-button class="filter-item" type="primary" v-waves icon="el-icon-search" @click="getList">{{$t('table.search')}}</el-button>
				<el-button class="filter-item" type="warning" @click="userSet">未知事件提取策略</el-button>
				
			</el-row>
		</el-form>
		<el-table :data="list" v-loading="listLoading" element-loading-text="加载中..." border fit highlight-current-row @selection-change="handleSelectionChange" style="width: 100%">
			<el-table-column align="center" label="事件名称" min-width="100">
				<template slot-scope="scope">
					<el-button class="preview-button" type="text" @click="handleShow(scope.row);dialogStatus = true">{{scope.row.eventTitle}}</el-button>
				</template>
			</el-table-column>
			<el-table-column label="相关新闻" align="center" min-width="200">
				<template slot-scope="scope">
					<p v-for="(item, index) in scope.row.listNews" style="text-align: left;">{{ index + 1 }}.{{ item }}</p>
				</template>
			</el-table-column>
			<el-table-column label="事件标签" align="center" min-width="100">
				<template slot-scope="scope">
					<el-tag v-for="(tag, index) in scope.row.listTags" :key="tag.keyword" size="small">{{ tag.keyword }}</el-tag>
				</template>
			</el-table-column>
			<el-table-column prop="createTime" label="发现时间" align="center" width="100"></el-table-column>
			<el-table-column prop="updatetime" label="更新时间" align="center" width="100"></el-table-column>
			<el-table-column label="参考热度" align="center" width="140">
		        <template slot-scope="scope">
		        	<el-rate
		        		v-model="scope.row.eventHot"
		        		disabled
		        		void-icon-class="el-icon-aliFirefire"
		        		disabled-void-icon-class="el-icon-aliFirefire"
		        		:colors="['#d81e06', '#d81e06', '#d81e06']"
		        		:icon-classes="['el-icon-aliFirefire-fill', 'el-icon-aliFirefire-fill','el-icon-aliFirefire-fill']">
		        	</el-rate>
		        </template>
	    	</el-table-column>
			<el-table-column label="操作" align="center" width="150">
				<template slot-scope="scope">
					<el-button size="mini" @click="handleShow(scope.row);dialogStatus = false">编辑</el-button>
					<el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
				</template>
			</el-table-column>
		</el-table>
		<div class="pagination-container">
			<el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page.sync="listQuery.pageNum" :page-sizes="[10, 20, 30, 50]" :page-size="listQuery.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total">
			</el-pagination>
		</div>
		<el-dialog title="未知事件提取策略" :visible.sync="dialogFormUser" :closeOnClickModal='false'>
			<el-form :rules="unknownPlanRules" ref="unknownPlan" status-icon :model="unknownPlan" label-position="left" label-width="150px" style='margin: 24px;'>
				<el-form-item label="事件过期时间" prop="clusterExpirePeriod">
					<el-input v-model="unknownPlan.clusterExpirePeriod" :maxlength='11' placeholder="请输入大小在3至200的正整数">
						<template slot="append">天</template>
					</el-input>
				</el-form-item>
				<el-form-item label="事件发现资讯最小值" prop="clusterMinNewsNum">
					<el-input v-model="unknownPlan.clusterMinNewsNum" :maxlength='11' placeholder="请输入大小在5至300的正整数">
						<template slot="append">篇</template>
					</el-input>
				</el-form-item>
				<!--<el-form-item label="事件主副关键词阈值" prop="eventMainViceKeywordsThreshhold">
					<el-input v-model.number="unknownPlan.eventMainViceKeywordsThreshhold" @keyup.native="proving($event)" placeholder="请输入"></el-input>
				</el-form-item>-->
				<el-form-item label="事件发现间隔时间" prop="eventStartIntervalSecond">
					<el-input v-model="unknownPlan.eventStartIntervalSecond" @keyup.native="proving(unknownPlan.eventStartIntervalSecond)" :maxlength='11' placeholder="请输入大小在300至7200的正整数">
						<template slot="append">秒</template>
					</el-input>
				</el-form-item>
        <el-form-item label="事件热度计算周期" prop="eventHotPeriod">
        	<el-input v-model="unknownPlan.eventHotPeriod" :maxlength='11' placeholder="请输入">
        		<template slot="append">秒</template>
        	</el-input>
        </el-form-item>
				<el-form-item label="事件标签个数" prop="eventKeywordsNum">
					<el-input disabled v-model="unknownPlan.eventKeywordsNum">
						<template slot="append">个</template>
					</el-input>
				</el-form-item>
				<el-form-item label="最近资讯处理" prop="eventRefreshNwsSecond">
					<el-input disabled v-model="unknownPlan.eventRefreshNwsSecond">
						<template slot="append">秒</template>
					</el-input>
				</el-form-item>
				<!--<el-form-item label="计算周期" prop="computCycle">
					<el-select v-model="unknownPlan.computCycle" type="text" placeholder="请选择">
						<el-option v-for="item in computCycles" :key="item.code" :label="item.value" :value="item.code"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="交易日首日策略" prop="tradePolicy">
					<el-select v-model="unknownPlan.tradePolicy" type="text" placeholder="请选择">
						<el-option v-for="item in tradePolicys" :key="item.code" :label="item.value" :value="item.code"></el-option>
					</el-select>
				</el-form-item>-->
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click="dialogFormUser = false">取消</el-button>
				<el-button type="primary" @click="updateUser('unknownPlan')">确定</el-button>
			</div>
		</el-dialog>

		<el-dialog :fullscreen='true' :title="dialogStatus ? '未知事件详情': '未知事件编辑'" :visible.sync="dialogFormVisible">
			<el-form ref="temp" :model="temp" :rules="editRules" label-position="left" label-width="130px" style='margin: auto; max-width: 1200px'>
				<el-row :gutter="24">
					<el-col :span="12">
						<el-form-item label="事件名称" prop="eventTitle">
							<el-input :disabled='dialogStatus' v-model.trim="temp.eventTitle" type="text" placeholder="请输入"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="10">
						<el-form-item label="事件生命周期" prop="originTime">
							<el-date-picker disabled v-model="temp.originTime" type="datetime" placeholder=""></el-date-picker>
						</el-form-item>
					</el-col>
					<el-col :span="2">
						<span style="line-height: 39px;">——至今</span>
					</el-col>
					<el-col :span="12">
						<el-form-item label="事件标签">
							<el-select
								:disabled='dialogStatus'
								multiple
								:multiple-limit=5
								filterable
								remote
								reserve-keyword
								:remote-method="remoteMethod"
								:loading="searchloading"
								popper-class="select-rule"
								no-match-text="暂无信息"
								no-data-text="暂无信息"
								:default-first-option=true
								v-model="temp.listTags"
								placeholder="请选择"
								@change="selectShange">
								<el-option v-for="(item, index) in tagOptions" :key="item" :label="item" :value="item"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="事件热度" prop="eventHot">
							<el-rate
								style="line-height: 45px;"
								v-model="temp.eventHot"
								disabled
								void-icon-class="el-icon-aliFirefire"
								disabled-void-icon-class="el-icon-aliFirefire"
								:colors="['#d81e06', '#d81e06', '#d81e06']"
								:icon-classes="['el-icon-aliFirefire-fill', 'el-icon-aliFirefire-fill','el-icon-aliFirefire-fill']">
							</el-rate>
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label="相关产业链">
							<el-select v-model="temp.relatedChain" multiple filterable placeholder="请选择" :disabled='dialogStatus'>
							<el-option v-for="item in flowChartList" :key="item" :label="item" :value="item"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label="事件描述" prop="eventDescript">
							<el-input :disabled='dialogStatus' v-model="temp.eventDescript" type="textarea" :rows="5" placeholder="请输入"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label="相关资讯">
							<el-table stripe max-height="500" :data="listNewsInfo" style="width: 100%" border fit highlight-current-row>
								<el-table-column type="index" width="40" align="center"></el-table-column>
								<el-table-column label="标题" align="center" min-width="200">
									<template slot-scope="scope">
										<el-button class="preview-button" type="text" @click="showInfo(scope.row)">{{scope.row.title}}</el-button>
									</template>
								</el-table-column>
								<el-table-column prop="summary" label="摘要" align="center" min-width="300"></el-table-column>
								<el-table-column prop="createTime" label="创建时间" align="center" width="100"></el-table-column>
								<el-table-column prop="updateTime" label="更新时间" align="center" width="100"></el-table-column>
								<el-table-column prop="source" label="来源" align="center"></el-table-column>
								<el-table-column label="态度" align="center" width="65">
									<template slot-scope="scope">
										<span v-if="scope.row.attitude == -1" class="tagColor" style="background-color: #4cba2a;">&nbsp;利空&nbsp;</span>
										<span v-else-if="scope.row.attitude == 0" class="tagColor" style="background-color: #c5d106;">&nbsp;中性&nbsp;</span>
										<span v-else-if="scope.row.attitude == 1" class="tagColor" style="background-color: red;">&nbsp;利好&nbsp;</span>
									</template>
								</el-table-column>
							</el-table>
							<div class="pagination-container" style="margin-top: 10px;">
								<el-pagination background @size-change="newsSizeChange" @current-change="newsCurrentChange" :current-page.sync="newsObj.pageNum" :page-sizes="[10, 20, 30, 50]" :page-size="newsObj.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="newsTotal"></el-pagination>
							</div>
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label="相关股票">
							<el-table stripe max-height="500" :data="listStock" style="width: 100%" border fit highlight-current-row>
								<el-table-column type="index" width="40" align="center"></el-table-column>
								<el-table-column prop="code" label="股票代码" align="center"></el-table-column>
								<el-table-column prop="name" label="股票名称" align="center"></el-table-column>
								<el-table-column label="相关度" align="center">
									<template slot-scope="scope">
										<el-rate v-model="scope.row.similar" disabled></el-rate>
									</template>
								</el-table-column>
							</el-table>
							<div class="pagination-container" style="margin-top: 10px;">
								<el-pagination background @size-change="stocksSizeChange" @current-change="stocksCurrentChange" :current-page.sync="stocksObj.pageNum" :page-sizes="[10, 20, 30, 50]" :page-size="stocksObj.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="stocksTotal"></el-pagination>
							</div>
						</el-form-item>
					</el-col>
				</el-row>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button v-if="!dialogStatus" type="success" @click="addMethod">加入已知</el-button>
				<el-button type="primary" @click="dialogFormVisible = false">关闭</el-button>
			</div>
			<el-dialog append-to-body :fullscreen='true' :title="infoTitle" :visible.sync="dialogInfo">
				<div v-if='dialogInfo'>
					<infoPreview :infoMsg='infoMsg' @closeFile='closeFile'></infoPreview>
				</div>
			</el-dialog>
		</el-dialog>
		<el-dialog :fullscreen='true' title="未知事件添加" :visible.sync="dialogFormVisible1">
			<el-form ref="temp1" :model="temp" :rules="editRules" label-position="left" label-width="130px" style='margin: auto; max-width: 1200px'>
				<el-row :gutter="24">
					<el-col :span="12">
						<el-form-item label="事件名称" prop="eventTitle">
							<el-input  v-model.trim="temp.eventTitle" type="text" placeholder="请输入"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="10">
						<el-form-item label="事件生命周期" prop="originTime">
							<el-date-picker disabled v-model="temp.originTime" type="datetime" placeholder=""></el-date-picker>
						</el-form-item>
					</el-col>
					<el-col :span="2">
						<span style="line-height: 39px;">——至今</span>
					</el-col>
					<el-col :span="12">
						<el-form-item label="事件标签">
							<el-select
								:disabled='dialogStatus'
								multiple
								:multiple-limit=5
								filterable
								remote
								reserve-keyword
								:remote-method="remoteMethod"
								:loading="searchloading"
								popper-class="select-rule"
								no-match-text="暂无信息"
								no-data-text="暂无信息"
								:default-first-option=true
								v-model="temp.listTags"
								placeholder="请选择"
								@change="selectShange">
								<el-option v-for="(item, index) in tagOptions" :key="item" :label="item" :value="item"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="事件热度" prop="eventHot">
							<el-rate
								style="line-height: 45px;"
								v-model="temp.eventHot"
								void-icon-class="el-icon-aliFirefire"
								disabled-void-icon-class="el-icon-aliFirefire"
								:colors="['#d81e06', '#d81e06', '#d81e06']"
								:icon-classes="['el-icon-aliFirefire-fill', 'el-icon-aliFirefire-fill','el-icon-aliFirefire-fill']">
							</el-rate>
						</el-form-item>
					</el-col>
					<!-- <el-col :span="24">
						<el-form-item label="相关产业链">
							<el-select v-model="temp.relatedChain" multiple filterable placeholder="请选择" :disabled='dialogStatus'>
							<el-option v-for="item in flowChartList" :key="item" :label="item" :value="item"></el-option>
							</el-select>
						</el-form-item>
					</el-col> -->
					<el-col :span="24">
						<el-form-item label="事件描述" prop="eventDescript">
							<el-input :disabled='dialogStatus' v-model="temp.eventDescript" type="textarea" :rows="5" placeholder="请输入"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label="查询资讯" @keyup.enter.native="getSearchInfo(searchWord)">
							<el-input v-model="searchWord" type="text" placeholder="请输入">
								<el-button slot="append" icon="el-icon-search" @keyup.enter.native="getSearchInfo(searchWord)" @click='getSearchInfo(searchWord)'></el-button>
							</el-input>
							<el-table stripe max-height="500" :data="listSearchNewsInfo" style="width: 100%" border fit highlight-current-row>
								<el-table-column type="index" width="40" align="center"></el-table-column>
								<el-table-column label="标题" align="center" min-width="200">
									<template slot-scope="scope">
										<el-button class="preview-button" type="text" @click="showInfo(scope.row)">{{scope.row.title}}</el-button>
									</template>
								</el-table-column>
								<el-table-column prop="summary" label="摘要" align="center" min-width="300"></el-table-column>
								<el-table-column prop="createTime" label="创建时间" align="center" width="100"></el-table-column>
								<el-table-column prop="updateTime" label="更新时间" align="center" width="100"></el-table-column>
								<el-table-column prop="source" label="来源" align="center"></el-table-column>
								<el-table-column label="态度" align="center" width="65">
									<template slot-scope="scope">
										<span v-if="scope.row.attitude == -1" class="tagColor" style="background-color: #4cba2a;">&nbsp;利空&nbsp;</span>
										<span v-else-if="scope.row.attitude == 0" class="tagColor" style="background-color: #c5d106;">&nbsp;中性&nbsp;</span>
										<span v-else-if="scope.row.attitude == 1" class="tagColor" style="background-color: red;">&nbsp;利好&nbsp;</span>
									</template>
								</el-table-column>
								<el-table-column align="center" label="操作" width="150" class-name="small-padding fixed-width" v-if='!dialogStatus'>
									<template slot-scope="scope">
										<el-button style="width: auto" type="success" size="mini" @click.native.prevent="addNews(scope.row)">添加</el-button>
									</template>
								</el-table-column>
							</el-table>
							<div class="pagination-container" style="margin-top: 10px;">
								<el-pagination background @size-change="newsSearchSizeChange" @current-change="newsSearchCurrentChange" :current-page.sync="newsSearchObj.pageNum" :page-sizes="[10, 20, 30, 50]" :page-size="newsSearchObj.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="newsSearchTotal"></el-pagination>
							</div>
						</el-form-item>
						
					</el-col>
					
					<el-col :span="24">
						<el-form-item label="相关资讯">
							<el-table stripe max-height="500" :data="temp.listNewsInfo" style="width: 100%" border fit highlight-current-row>
								<el-table-column type="index" width="40" align="center"></el-table-column>
								<el-table-column label="标题" align="center" min-width="200">
									<template slot-scope="scope">
										<el-button class="preview-button" type="text" @click="showInfo(scope.row)">{{scope.row.title}}</el-button>
									</template>
								</el-table-column>
								<el-table-column prop="summary" label="摘要" align="center" min-width="300"></el-table-column>
								<el-table-column prop="createTime" label="创建时间" align="center" width="100"></el-table-column>
								<el-table-column prop="updateTime" label="更新时间" align="center" width="100"></el-table-column>
								<el-table-column prop="source" label="来源" align="center"></el-table-column>
								<el-table-column label="态度" align="center" width="65">
									<template slot-scope="scope">
										<span v-if="scope.row.attitude == -1" class="tagColor" style="background-color: #4cba2a;">&nbsp;利空&nbsp;</span>
										<span v-else-if="scope.row.attitude == 0" class="tagColor" style="background-color: #c5d106;">&nbsp;中性&nbsp;</span>
										<span v-else-if="scope.row.attitude == 1" class="tagColor" style="background-color: red;">&nbsp;利好&nbsp;</span>
									</template>
								</el-table-column>
								<el-table-column align="center" label="操作" width="150" class-name="small-padding fixed-width" >
									<template slot-scope="scope">
										<el-button style="width: auto" type="danger" size="mini" @click.native.prevent="delNews(scope.row)">移除</el-button>
									</template>
								</el-table-column>
							</el-table>
						</el-form-item>
					</el-col>
					<!-- <el-col :span="24">
						<el-form-item label="相关股票">
							<el-table stripe max-height="500" :data="listStock" style="width: 100%" border fit highlight-current-row>
								<el-table-column type="index" width="40" align="center"></el-table-column>
								<el-table-column prop="code" label="股票代码" align="center"></el-table-column>
								<el-table-column prop="name" label="股票名称" align="center"></el-table-column>
								<el-table-column label="相关度" align="center">
									<template slot-scope="scope">
										<el-rate v-model="scope.row.similar" disabled></el-rate>
									</template>
								</el-table-column>
							</el-table>
							<div class="pagination-container" style="margin-top: 10px;">
								<el-pagination background @size-change="stocksSizeChange" @current-change="stocksCurrentChange" :current-page.sync="stocksObj.pageNum" :page-sizes="[10, 20, 30, 50]" :page-size="stocksObj.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="stocksTotal"></el-pagination>
							</div>
						</el-form-item>
					</el-col> -->
				</el-row>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button type="success" @click="addUnknowMethod">加入未知</el-button>
				<el-button type="primary" @click="dialogFormVisible1 = false">关闭</el-button>
			</div>
		</el-dialog>
	</div>
</template>

<script>
	import { eventsList, eventsDelete, eventGet, selectByIdNews, selectByIdChains, selectByIdStocks, eventsSetList, getEventsSetInfo, evSetUpdate, unknownEventJoin,eventJoin, getAllTags, searchInfo,listAllInfo } from '@/api/events'
	import { getChartList } from '@/api/article'
  	import waves from '@/directive/waves' // 水波纹指令
	import infoPreview from './infoPreview'
	// import newsTable from './newsTable'
	// import stocksTable from './stocksTable'

	export default {
		name: 'unknownEvtManage',
		components: { infoPreview },
		directives: {
			waves
		},
		data() {
			let checkMethod = function(val, num, big, back){
				let reg = /^[+]{0,1}(\d+)$/g;
				let str = `请输入大小在${num}至${big}的正整数`
				if (!reg.test(val)) {
					back(new Error(str))
				} else {
					if(val < num || val > big){
						back(new Error(str))
					} else {
						back()
					}
				}
			}
			let timeGapPass = (rule, value, callback) => {
				checkMethod(value, 3, 200, callback)
			}
			let timeGapPass01 = (rule, value, callback) => {
				checkMethod(value, 5, 300, callback)
			}
			let timeGapPass02 = (rule, value, callback) => {
				checkMethod(value, 5, 10, callback)
			}
			let timeGapPass03 = (rule, value, callback) => {
				checkMethod(value, 300, 7200, callback)
			}
			let timeGapPass04 = (rule, value, callback) => {
				checkMethod(value, 300, 2592000, callback)
			}
			return {
				tableKey: 0,
				list: null,
				total: null,
				newsTotal: null,
				newsSearchTotal:null,
				stocksTotal: null,
				evtId: '',
				listLoading: true,
				multipleSelection: [],
				multipleSelectionIds: [],
				dialogFormUser: false,
				dialogFormVisible: false,
				dialogFormVisible1: false,
				searchWord:'',
				listSearchNewsInfo:[],
				dialogVisible: false,
				dialogInfo:false,
				infoTitle:'',
				newsObj: {
					pageNum: 1,
					pageSize: 20,
					eventId: ''
				},
				newsSearchObj: {
					pageNum: 1,
					pageSize: 20,
				},
				stocksObj: {
					pageNum: 1,
					pageSize: 20,
					eventId: ''
				},
				listQuery: {
					pageNum: 1,
					pageSize: 10,
					dataStatus: 0,
					eventTitle: '',
					keyword: '',
					startTime: '',
					endTime: '',
					foundTime: []
//					foundTime: [new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate() + 1).getTime() - 24 * 3600 * 1000, new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate() + 1).getTime() - 1000],
				},
				unknownPlan: {},
				unknownPlanRules: {
				clusterExpirePeriod: [
//						{ required: true, type: 'number', message: '请输入大小在3至200的正整数', trigger: 'blur' },
					{ required: true, validator: timeGapPass, trigger: 'blur' }
				],
				clusterMinNewsNum: [
					{ required: true, validator: timeGapPass01, trigger: 'blur' }
				],
				eventStartIntervalSecond: [
					{ required: true, validator: timeGapPass03, trigger: 'blur' }
				],
				eventHotPeriod: [
					{ required: true, validator: timeGapPass04, trigger: 'blur' }
				]
				},
				addKnownRules: {
				},
				editRules: {
					eventTitle: [{ required: true, message: '请输入事件名称', trigger: 'blur' }]
				},
				temp: {
					eventTitle: '',
					originTime: '',
					listTags: [],
					eventHot: ''
					// listNewsInfo: [],
					// listStock: []
				},
				listNewsInfo: [],
				listStock :[],
				dialogStatus: false,
				tagOptions: [],
        		flowChartList: [],
				searchloading: false,
				tagList: [],  //懒加载中间件
		        addKnown:{
		        	addKnownTag:[],
		        	describe:''
		        },
		        infoMsg: {},
		        evtMsg: {
		        	apiTar: 'selectByIdNews',
		        	evtId: '',
		        	deleteBtn: false,
		        	readonly: true
		        },
		        stockMsg: {
		        	apiTar: 'selectByIdStocks',
		        	evtId: '',
		        	deleteBtn: false,
		        	readonly: true
		        },
//		        computCycles: [],
//		        tradePolicys: [],
				pickerOptions: {
					shortcuts: [{
						text: '今天',
						onClick(picker) {
							const end = new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate() + 1).getTime() - 1000
							const start = end + 1000 - 3600 * 1000 * 24
							picker.$emit('pick', [start, end])
						}
					}, {
						text: '最近三天',
						onClick(picker) {
							const end = new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate() + 1).getTime() - 1000
							const start = end + 1000 - 3600 * 1000 * 24 * 3
							picker.$emit('pick', [start, end])
						}
					}, {
						text: '最近一周',
						onClick(picker) {
							const end = new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate() + 1).getTime() - 1000
							const start = end + 1000 - 3600 * 1000 * 24 * 7
							picker.$emit('pick', [start, end])
						}
					}]
				}
			}
		},
	  	computed: {
    		eventRefreshNwsSecond: function () {
      			return this.unknownPlan.eventStartIntervalSecond + 300
    		}
  		},
		created() {
			this.getList()
			// this.init()
		},
		methods: {
			getList() {
				this.listLoading = true
				const params = Object.assign({}, this.listQuery)
				if(this.listQuery.foundTime) {
					params.startTime = this.listQuery.foundTime[0]
					params.endTime = this.listQuery.foundTime[1]
				}
				eventsList(params).then(res => {
					this.listLoading = false
					this.list = res.Data
					this.total = parseInt(res.total)
				})
			},
			handleSizeChange(val) {
				this.listQuery.pageSize = val
				this.getList()
			},
			handleCurrentChange(val) {
				this.listQuery.pageNum = val
				this.getList()
			},
			getNewsList(tar) {
				this.newsObj.eventId = tar
				selectByIdNews(this.newsObj).then(res => {
					this.listNewsInfo = Object.assign([], res.Data)
					this.newsTotal = parseInt(res.total)
				})
			},
			newsSizeChange(val) {
				this.newsObj.pageSize = val
				this.getNewsList(this.evtId)
			},
			newsCurrentChange(val) {
				this.newsObj.pageNum = val
				this.getNewsList(this.evtId)
			},
			newsSearchSizeChange(val){
				this.newsSearchObj.pageSize = val;
				this.getSearchInfo(this.searchWord);
			},
			newsSearchCurrentChange(val){
				this.newsSearchObj.pageNum = val;
				this.getSearchInfo(this.searchWord);
			},
			addNews(row){
				var newsId = row.newsId;
				var isExist = false;
				for(var i =0;i<this.temp.listNewsInfo.length;i++){
					if(newsId === this.temp.listNewsInfo[i].newsId){
						isExist = true;
						this.$message({
							message: '',
							type: 'warning'
							});
							break;
					}
				};
				this.temp.listNewsInfo.push(row);
				this.$message({
					message: '添加资讯成功',
					type: 'success'
				});
},
			delNews(row){
				var newsId = row.newsId;
				var index = 0;
				for(var i =0;i<this.temp.listNewsInfo.length;i++){
					if(newsId === this.temp.listNewsInfo[i].newsId){
						this.temp.listNewsInfo.splice(i,1)
						this.$message({
							message: '移除资讯成功',
							type: 'success'
						});
						break;
					}
				};
			},
			getStocksList(tar) {
				this.stocksObj.eventId = tar
				selectByIdStocks(this.stocksObj).then(res => {
					this.listStock = Object.assign([], res.Data)
					this.stocksTotal = parseInt(res.total)
				})
			},
			stocksSizeChange(val) {
				this.stocksObj.pageSize = val
				this.getStocksList(this.evtId)
			},
			stocksCurrentChange(val) {
				this.stocksObj.pageNum = val
				this.getStocksList(this.evtId)
			},
			init(){
//				eventsSetList().then(res => {
//					let tar = res.Data[0] || []
//					this.computCycles = Object.assign([], tar.computCycles)
//					this.tradePolicys = Object.assign([], tar.tradePolicys)
//				})
				getAllTags().then(res => {
					let dta = res.Data || []
					this.tagOptions = Object.assign([], dta)
				})
			},
			selectShange(item){
				this.$forceUpdate()  //绑定了对象（需求如此），render函数没有自动更新，数据刷新了，但是视图没有刷新
			},
			handleSelectionChange(val) {
				this.multipleSelection = val
				this.multipleSelectionIds = val.map(e => e.id)
			},
			userSet() {
				getEventsSetInfo().then(res => {
					let tar = res.Data[0] || {}
					this.unknownPlan = Object.assign({}, tar)
					this.unknownPlan.eventKeywordsNum = 5
					this.unknownPlan.eventRefreshNwsSecond = this.unknownPlan.eventStartIntervalSecond + 300
					this.dialogFormUser = true
					this.$nextTick(() => {
						this.$refs['unknownPlan'].clearValidate()
					})
				})
			},
			proving(num) {
				this.unknownPlan.eventRefreshNwsSecond = num * 1 + 300
			},
			updateUser(formName) {
				this.$refs[formName].validate(valid => {
					if(valid) {
					    evSetUpdate(this.unknownPlan).then(() => {
							this.getList()
							this.dialogFormUser = false
							this.$notify({ title: '成功', message: '未知事件提取策略设置成功', type: 'success', duration: 5000 })
			    		})
					}
				})
			},
			handleDelete(row) {
				this.$confirm('确认删除, 是否继续?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
	          		eventsDelete(row).then(() => {
			            this.$notify({ title: '成功', message: '删除成功', type: 'success', duration: 2000 })
						this.getList()
		          	})
				}).catch(() => {
					this.$message({ type: 'info', message: '已取消删除' })
				})
			},
			showInfo(row) {
				if(row.srcType == 1 || row.srcType == 2){
					this.infoMsg = Object.assign({}, row)
					this.infoTitle = '资讯详情'
					this.dialogInfo = true
				} else {
					this.$message({ type: 'info', message: '获取资讯标识失败' })
				}
			},
			resetTemp () {
				this.temp = {
					eventTitle:"",
					listTags:[],
					eventHot:0,
					eventDescript:"",
					listNewsInfo:[]
				}
			},
			handleAdd(){
				this.resetTemp();
				this.listSearchNewsInfo = [];
				this.dialogFormVisible1 = true;
				this.$nextTick(() => {
					this.$refs['temp1'].clearValidate()
				});
				if(this.tagList.length == 0) this.getSelectList();
			},
			
			// 搜索资讯
			getSearchInfo(e) {
				if (e.trim() === '') {
					this.$message({
						type: 'warning',
						message: '请输入有效查询内容！'
					})
					return
				}
				const params = {
					pageNum: this.newsSearchObj.pageNum,
					pageSize: this.newsSearchObj.pageSize,
					conditions: e
				}
				searchInfo(params).then(res => {
					this.listSearchNewsInfo = Object.assign([], res.Data)
					this.newsSearchTotal = parseInt(res.total);
				})
			},
			handleShow(row) {
				eventGet(row).then(res => {
					this.evtId = row.eventId
					// this.evtMsg.evtId = row.eventId
					// this.stockMsg.evtId = row.eventId
					this.temp = Object.assign({}, res.Data[0])
					this.temp.listTags = this.temp.listTags.map(e => {return e.keyword})
					this.getNewsList(row.eventId)
					this.getStocksList(row.eventId)
          			this.getRelatedChain(row.eventId)
					this.dialogFormVisible = true
					this.$nextTick(() => {
						this.$refs['temp'].clearValidate()
					})
				})
				if(this.tagList.length == 0) this.getSelectList()
			},
			getRelatedChain(tar){
				selectByIdChains({'eventId': tar}).then(res => {
					this.temp.relatedChain = Object.assign([], res.Data)
				})
			},
			getSelectList() {
				listAllInfo().then(res => {
					this.tagList = res.Data[0]
				})
				getChartList().then(res => {
					this.flowChartList = res.Data
				})
			},
			remoteMethod(query) {
			  if (query !== '') {
			    this.searchloading = true;
			    setTimeout(() => {
			      this.searchloading = false;
			      this.tagOptions = this.tagList.filter(item => {
					return item.toLowerCase().indexOf(query.toLowerCase()) > -1;
			      });
			    }, 200);
			  } else {
			    this.tagOptions = [];
			  }
			},
			addUnknowMethod(){
				this.$refs['temp1'].validate(valid => {
					if(valid) {
						let obj = Object.assign({}, this.temp)
						obj.listTags = obj.listTags.map(e => {return { 'keyword': e}})
						obj.listNews = obj.listNewsInfo.map(e=>{return e.newsId})
					    unknownEventJoin(obj).then(() => {
							this.getList()
							this.dialogFormVisible1 = false
							this.$notify({ title: '成功', message: '加入未知事件成功', type: 'success', duration: 5000 })
			    		})
					}
				})
			},
			addMethod(){
				this.$refs['temp'].validate(valid => {
					if(valid) {
						let obj = Object.assign({}, this.temp)
						obj.listTags = obj.listTags.map(e => {return { 'keyword': e, 'type': 1 }})
						delete obj.listNewsInfo
						delete obj.listStock
					    eventJoin(obj).then(() => {
							this.getList()
							this.dialogFormVisible = false
							this.$notify({ title: '成功', message: '加入已知事件成功', type: 'success', duration: 5000 })
			    		})
					}
				})
			},
			closeFile() {
				this.dialogInfo = false
			},
      		attitudeTagColor(num) {
	    		switch (num) {
		          case -1:
		            return 'success'
		          case 0:
		            return ''
		          case 1:
		            return 'danger'
		        }
	      	},
	      	attitudeTag(num) {
	    		switch (num) {
		          case -1:
		            return '利空'
		          case 0:
		            return '中性'
		          case 1:
		            return '利好'
		        }
	      	}
		}
	}
</script>

<style scoped>
	.el-tag {
		margin-right: 5px;
	}
	.tagColor{
		color: white;
		border-radius: 5px;
	}
	.el-tooltip__popper {
		max-width: 800px;
		margin: auto;
	}
</style>
